package com.itheima.mapper;

import com.itheima.pojo.Emp;
import com.itheima.pojo.EmpQueryParam;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

//员工信息
@Mapper
public interface EmpMapper {
    //查询员工信息
    List<Emp> list(EmpQueryParam empQueryParam);


    @Options(useGeneratedKeys = true,keyProperty = "id")//获取生成的主键--主键返回
    @Insert("insert into emp (username,password,name,gender,phone,job,salary,image,entry_date,dept_id,create_time,update_time) " +
            "values (#{username},#{password},#{name},#{gender},#{phone},#{job},#{salary},#{image},#{entryDate},#{deptId},#{createTime},#{updateTime})")
    void insert(Emp emp);

    void deleteByIds(List<Integer> ids);

    //根据id查询员工信息以及工作经历信息
    Emp getById(Integer id);



//    //根据id更新员工的基本信息
    void updateById(Emp emp);


    //统计员工职位数量
    @MapKey("pos")
    List<Map<String,Object>> countEmpJobDate();

    @MapKey("name")
    List<Map<String, Object>> countEmpGenderData();

    @Select("select id,username,password,name,gender,image,job,salary,entry_date entryDate,dept_id deptId,create_time createTime,update_time updateTime from emp")
    List<Emp> findEmp();

    /**
     * 根据用户名和密码查询员工信息
     */
    @Select("select * from emp where username = #{username} and password = #{password}")
    Emp getUsernameAndPassword(Emp emp);


    //----------------------------------原始方式------------------------------------------
    //查询总记录数
//    @Select("select count(*) from emp e left join dept d on e.dept_id = d.id")
//    public Long count();
//
//    //执行分页查询
//    @Select("select e.*,d.name deptName from emp e left join dept d on e.dept_id = d.id order by e.update_time desc limit #{start},#{pageSize}")
//    public List<Emp> list(Integer start, Integer pageSize);

    //----------------------------------插件方式------------------------------------------
   // @Select("select e.*,d.name deptName from emp e left join dept d on e.dept_id = d.id order by e.update_time desc")
    //public List<Emp> list(EmpQueryParam empQueryParam);
}
